package com.eportal.struts.interceptor;


import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.eportal.util.MD5;
import com.eportal.util.Tools;
import com.framework.ActionUtil;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

/** session过期、登录有效性及操作的权限验证拦截器 */
public class WebServiceCheckInterceptor extends AbstractInterceptor {

	/** 拦截请求并进行登录有效性验证 */
	public String intercept(ActionInvocation ai) throws Exception {
		//取得请求的URL
		String url = ServletActionContext.getRequest().getRequestURL().toString();
		HttpServletResponse httpResponse = ServletActionContext.getResponse();
		httpResponse.setHeader("Pragma","No-cache");   
		httpResponse.setHeader("Cache-Control","no-cache");  
		httpResponse.setDateHeader("Expires", 0);  
		
		String prim = null;
		int index = 0;
		//对登录与注销请求直接放行,不予拦截
		if(url.indexOf("webService/webService")>-1){
			String p="";
			TreeMap<?, ?> tempmap=(TreeMap)Tools.getParameterMap(ServletActionContext.getRequest());
			Iterator iter = tempmap.entrySet().iterator(); 
  	    	 while (iter.hasNext()) { 
  	    	Map.Entry entry = (Map.Entry) iter.next(); 
  	    	 Object key = entry.getKey(); 
  	    	 if(!(key.toString()).equals("method")&&!(key.toString()).equals("sign")){
  	    		 p=p+entry.getValue();
  	    	 }
  	    	 }
  	    	return ai.invoke();
   		
		}
		return ai.invoke();
		}
	}

